#include <stdio.h>
#include <vector>
#include "coin.h"
using namespace std;
int main()
{
  int n;
  int a[4];
  cin>>n;
  for(int i=0;i<4;i++){
    cin>>a[i];
  }
  int result=coinChange(n,a);
  if(result==-1) {cout<<"fail to change"<<endl;}
  else {cout<<result<<endl;}
  return 0;
}
	     


